package com.grademaster.controller;

import com.grademaster.common.R;
import com.grademaster.dto.TermPageDto;
import com.grademaster.entity.Terms;
import com.grademaster.service.TermsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/terms")
@Api(tags = "学期相关接口")
@CrossOrigin(origins = {"http://localhost:8081"}, allowCredentials = "true")
public class TermsController {

    @Autowired
    private TermsService termsService;


    @ApiOperation("获取教师相关的学期数据")
    @GetMapping("/listByTeacher")
    public R getTermsListByTeacher() {
        return termsService.getTermsListByTeacher();
    }

    @ApiOperation("获取学生相关的学期数据")
    @GetMapping("/listByStudent")
    public R getTermsListByStudent() {
        return termsService.getTermsListByStudent();
    }

    @ApiOperation("获取所有学期信息")
    @GetMapping("/getAllTerms")
    public R getAllTerms() {
        return termsService.getAllTerms();
    }

    @ApiOperation("获取所有学期分页信息")
    @GetMapping("/getAllTermsByPage")
    public R getAllTermsByPage(TermPageDto termPageDto) {
        return termsService.getAllTermsByPage(termPageDto);
    }
    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel")
    public ResponseEntity exportExcel(TermPageDto termPageDto){
        return termsService.exportExcel(termPageDto);
    }

    @ApiOperation("添加或修改学期")
    @PostMapping("/addOrEditTerm")
    public R addOrEditTerm(@RequestBody Terms terms) {
        return termsService.addOrEditTerm(terms);
    }

    @ApiOperation("删除学期")
    @DeleteMapping("/deleteTerm/{termId}")
    public R deleteTerm(@PathVariable("termId") String termId) {
        return termsService.deleteTerm(termId);
    }
}
